package com.dong.mcd.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

import com.dong.mcd.pub.Constants;


/**
 * @author willy chen
 * @createTime 2011-3-12 下午02:57:17
 * @desc Json处理java对象到json格式转换的日期处理类
 * 
 */
public class JsonDateValueProcessor implements JsonValueProcessor {

	private String datePattern = Constants.Date.LONG_DATE_PATTERN;

	public JsonDateValueProcessor() {
		super();
	}

	// 构造函数
	public JsonDateValueProcessor(String format) {
		super();
		this.datePattern = format;
	}

	public Object processArrayValue(Object value, JsonConfig jsonConfig) {
		// TODO Auto-generated method stub
		return process(value);
	}

	public Object processObjectValue(String key, Object value,
			JsonConfig jsonConfig) {
		// TODO Auto-generated method stub
		return process(value);
	}

	private Object process(Object value) {
		
		if (value != null) {
			DateFormat dateFormat = new SimpleDateFormat(Constants.Date.LONG_DATE_PATTERN);
			return dateFormat.format((Date) value);
		}
		return value;
	}

	public String getDatePattern() {
		return datePattern;
	}

	public void setDatePattern(String datePaterns) {
		this.datePattern = datePaterns;
	}

}
